<?php

namespace app\http\middleware;
use app\backstage\model\Admin;
class CheckLogin
{
    public function handle($request, \Closure $next)
    {

        $login_token = cookie('login_token');
        //未登录跳转到登录页
        if(!$login_token){
            return redirect(config('template.root_path').'/login');
        }

        $row = Admin::where('login_token',$login_token)->find();

        //token失效
        if(!$row){
            return redirect(config('template.root_path').'/login');
        }

        $request->role_id = $row['role_id'];
        $request->admin_id = $row['id'];
        return $next($request);
    }
}
